﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using DevExpress.Xpf.Grid;

namespace Views {



    public static class GridItemSourceDp {
        public static readonly DependencyProperty BindableGridItemSourceProperty =
           DependencyProperty.RegisterAttached("BindableSource", typeof(object), typeof(GridItemSourceDp), new UIPropertyMetadata(null, BindableSourcePropertyChanged));

        public static object GetBindableSource(DependencyObject obj) {
            return  obj.GetValue(BindableGridItemSourceProperty);
        }

        public static void SetBindableSource(DependencyObject obj, object value) {
            obj.SetValue(BindableGridItemSourceProperty, value);
        }

        public static void BindableSourcePropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) {
            GridControl grid = o as GridControl;
            if (grid != null) {
                object list = e.NewValue;
                grid.Columns.Clear();
                grid.ItemsSource = list;
                grid.RefreshData();
            }
        }
    }
}
